{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Write a YAML file based on fetching a material document that\n",
    "includes keys not currently accounted for by the API repository.\n",
    "\"\"\"\n",
    "\n",
    "import json\n",
    "import os\n",
    "import yaml\n",
    "from bson.json_util import dumps as bson_dumps\n",
    "from pymongo import MongoClient\n",
    "\n",
    "# http://docs.mongodb.org/manual/reference/connection-string/\n",
    "client = MongoClient(os.environ[\"MP_DB_CONN\"])\n",
    "materials = client[os.environ[\"MP_DB_NAME\"]]['materials']\n",
    "\n",
    "doc = json.loads(bson_dumps(materials.find_one({'task_id': 'mp-188'})))\n",
    "\n",
    "with open(\"mp-188.yaml\", \"w\") as f:\n",
    "    yaml.safe_dump(doc, f, default_flow_style=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
